package com.ganjingcun.roma.persist.dao;

import com.ganjingcun.roma.persist.model.Place;
import com.ganjingcun.roma.persist.utils.SessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by GanJc on 2016/4/16.
 */
public class PlaceDao {


    public void insertPlace(Place place){
        SqlSession session = SessionUtil.getSession();
        session.insert("com.chukong.adcore.persist.model.PlaceMapper.insertPlace",place);
        session.commit();
        session.close();
    }

    public List<Place> getPlaceList(int page){
        SqlSession session = SessionUtil.getSession();
        int start = 0;
        int pageSize = 10 ;
        int end = pageSize ;
        if(page>0){
            start = (page-1) * pageSize;
            end = start + pageSize ;
        }
        Map param = new HashMap();
        param.put("start",start);
        param.put("end",end);

        List<Place> placeList = session.selectList("com.chukong.adcore.persist.model.PlaceMapper.selectList", param);
        session.close();
        return placeList ;
    }

    public static void main(String[] args) {
        PlaceDao dao = new PlaceDao();
        List<Place> placeList = dao.getPlaceList(1);
        for (Place place : placeList) {
            System.out.println(place);
        }

    }
}
